package algebra.query.od;

import option.QueryKeywords;
import utils.Display;
import utils.exception.CoreReasoningException;
import utils.exception.OrderingDescriptionException;
import entities.assertion.ConceptAssertion;
import entities.concept.Concept;

@Deprecated
/**
 * A subsumption based ordering
 * 
 * @author j55wu
 * 
 */
public class OrderDepSub extends OrderDep {
	private OrderDep sub;

	public OrderDepSub(OrderDep sub) {
		this.sub = sub;
	}

	public OrderDep getSubOd() {
		return this.sub;
	}

	protected int compareOdSubsume(ConceptAssertion ca1, ConceptAssertion ca2)
			throws OrderingDescriptionException, CoreReasoningException {
		// is ca1 to be ordered before ca2?
		Concept c1 = ca1.getConcept(), c2 = ca2.getConcept();
		boolean cond1 = OdSubsumes(c1, c2, null); // if c1 -> c2
		boolean cond2 = OdSubsumes(c2, c1, null); // if c2 -> c1
		if (cond1 && !cond2) {
			return -1;
		} else if (cond2 && !cond1) {
			return 1;
		} else {
			// c1 == c2 or c1 <> c2, incomparable
			return this.sub.compare(ca1, ca2);
		}
	}

	@Override
	public String toString() {
		return "(OD: " + Display.IMPLIESUNICODE + " " + sub.toString() + ")";
	}

	@Override
	public String toSerializedString() {
		return "(" + QueryKeywords.Od_Subsume + " "
				+ this.sub.toSerializedString() + ")";
	}

}
